﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Controller;

public partial class Cliente : System.Web.UI.Page
{
    private DS_Lawyer.ClienteDataTable dtCliente
    {
        set { ViewState["dtCliente"] = value; }
        get
        {
            object o = ViewState["dtCliente"];
            if (o == null)
                return null;
            else
                return (DS_Lawyer.ClienteDataTable)o;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            try
            {
                this.dtCliente = cntrCliente.Select();
                grdCliente.DataSource = this.dtCliente;
                grdCliente.DataBind();
            }
            catch (Exception ex)
            {

                throw (new Exception(ex.Message));
            }
        }
    }
 
    protected void grdCliente_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            
            cntrCliente.Delete(this.dtCliente[e.RowIndex].idCliente);

            this.dtCliente = cntrCliente.Select();
            grdCliente.DataSource = this.dtCliente;
            grdCliente.DataBind();
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));

        }
       
    }

    protected void grdCliente_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        int index = Convert.ToInt32(e.CommandArgument);
        string idCliente = this.dtCliente[index].idCliente;

        switch (e.CommandName)
        {
            case "Edit":
               Response.Redirect("NewClient.aspx?IDCliente=" + idCliente);
            break;

            case "Relato":
               Response.Redirect("ShowRelato.aspx?IDCliente=" + idCliente);
            break;
                
            case "Processos":
                Response.Redirect("Processo.aspx?IDCliente=" + idCliente);
            break;
        }

    }

    protected void btnPesquisar_Click(object sender, ImageClickEventArgs e)
    {
        string criterio = txtBuscaNome.Text.Trim() + "%";

        this.dtCliente = cntrCliente.SelectByNome(criterio);
        grdCliente.DataSource = this.dtCliente;
        grdCliente.DataBind();
       
    }
}
